package com.utf999.qiangmanger.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Component;

import com.utf999.qiangmanger.dao.AbstractRelationalDBDAO;
import com.utf999.qiangmanger.dao.iface.ICompanyDAO;
import com.utf999.qiangmanger.entity.orm.CompanyEntity;
import com.utf999.qiangmanger.exception.BizException;
import com.utf999.qiangmanger.exception.ResponseCode;

/**
 * @author yinwenjie
 */
@Component("CompanyDAOImpl")
public class CompanyDAOImpl extends AbstractRelationalDBDAO<CompanyEntity> implements ICompanyDAO {

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.AbstractRelationalDBDAO#getEntityClass()
	 */
	@Override
	protected Class<CompanyEntity> getEntityClass() {
		return CompanyEntity.class;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.ICompanyDAO#queryCompanyList()
	 */
	//TODO 数据库未进行索引优化
	@Override
	public List<CompanyEntity> queryCompanyList(Integer status) throws BizException {
		HashMap<String, Object> condition = new HashMap<String, Object>();
		if(status != null) {
			condition.put("status", status);
		}
		List<CompanyEntity> companys = null;
		try {
			companys = this.queryByHqlFile("ICompanyDAO.queryCompanyList", condition);
		} catch (Exception e) {
			throw new BizException(e.getMessage(), ResponseCode.E501);
		}
		
		return companys;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.ICompanyDAO#queryCompanyByuserid(java.lang.String)
	 */
	//TODO 数据库未进行索引优化
	@Override
	public CompanyEntity queryCompanyByuserid(String adminuserid) throws BizException {
		HashMap<String, Object> condition = new HashMap<String, Object>();
		condition.put("adminuserid", adminuserid);
		List<CompanyEntity> companys = this.queryByHqlFile("ICompanyDAO.queryCompanyByuserid", condition);
		if(companys == null || companys.size() == 0) {
			return null;
		}
		
		return companys.get(0);
	}
}